package Com.javaserver.servlet;

import Com.javaserver.bean.departmentinquire;
import Com.javaserver.dao.departmentserver;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/dele")
public class departmentDeleteserverlet extends HttpServlet {
    departmentserver delesta = new departmentserver();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    //部门的删除接口
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        Integer ddelete = Integer.parseInt(req.getParameter("delete"));
        departmentinquire delepart = new departmentinquire();
        delepart.setD_ID(ddelete);

        departmentserver depar=new departmentserver();
        if (!delesta.dele(delepart)) {
            req.getSession().setAttribute("msg", "删除失败");
            resp.sendRedirect(req.getContextPath() + "/Department.jsp");
        } else {
            List<departmentinquire> list = depar.queryALl(1);
            System.out.println(list);
            req.getSession().setAttribute("deptList", list);
            req.getSession().setAttribute("msg", "删除成功");
            resp.sendRedirect(req.getContextPath() + "/Department.jsp");
        }
    }
}
